package JAVA300.第十章IO;

import java.io.File;
import java.util.Date;

/**
 * 利用面向对象思想进行文件夹大小的递归计算
 */
public class DirDemo02 {
    private long length;
    private String path;
    private File file;
    private int Filenum,dirNum;

    public DirDemo02( String path) {

        this.path = path;
        this.file = new File(path);
        DirCount(this.file);

    }

    private  void DirCount(File file){

        if (file == null || !file.exists()){
            return;
        }else{
            if (file.isDirectory()){
                this.dirNum++;
                for (File temp:file.listFiles()){
                    DirCount(temp);
                }
            }else {
                this.Filenum++;
                length = length + file.length();
            }
        }
    }

    public int getFilenum() {
        return Filenum;
    }

    public int getDirNum() {
        return dirNum;
    }

    public long getLength() {
        return length;
    }

    public static void main(String[] args) {
        DirDemo02 dirDemo02 = new DirDemo02("/Users/hqqs/Documents/CodeJava/JavaSE_Exp/src/JAVA300");

        System.out.println(dirDemo02.getLength()+"---"+dirDemo02.getDirNum()+"---"+dirDemo02.getFilenum());
    }
}
